package com.ruoyi.buss.grid.carInfo.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.buss.grid.carInfo.domain.CarBrand;
import com.ruoyi.buss.grid.carInfo.domain.CarInfo;
import com.ruoyi.buss.grid.carInfo.service.ICarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 车辆信息 DATA_CUSTOMER_INFO 外联Controller
 * 
 * @author zjh
 * @date 2021-10-12
 */
@RestController
@RequestMapping("/carInfo")
public class CarInfoController extends BaseController
{
    @Autowired
    private ICarInfoService carInfoService;

    /**
     * 查询车辆信息 DATA_CUSTOMER_INFO 外联列表
     */
    @PreAuthorize(hasPermi = "buss:carInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(CarInfo carInfo)
    {
        startPage();
        List<CarInfo> list = carInfoService.selectCarInfoList(carInfo);
        return getDataTable(list);
    }

    /**
     * 车辆品牌下拉表
     */
    @PreAuthorize(hasPermi = "buss:carInfo:getCarBrandInfo")
    @GetMapping("/getCarBrandInfo")
    public TableDataInfo getCarBrandInfo(CarBrand carBrand)
    {
        List<CarBrand> list = carInfoService.selectCarInfoList(carBrand);
        return getDataTable(list);
    }

    /**
     * 导出车辆信息 DATA_CUSTOMER_INFO 外联列表
     */
    @PreAuthorize(hasPermi = "buss:carInfo:export")
    @Log(title = "车辆信息 DATA_CUSTOMER_INFO 外联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarInfo carInfo) throws IOException
    {
        List<CarInfo> list = carInfoService.selectCarInfoList(carInfo);
        ExcelUtil<CarInfo> util = new ExcelUtil<CarInfo>(CarInfo.class);
        util.exportExcel(response, list, "车辆信息 DATA_CUSTOMER_INFO 外联数据");
    }

    /**
     * 获取车辆信息 DATA_CUSTOMER_INFO 外联详细信息
     */
    @PreAuthorize(hasPermi = "buss:carInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(carInfoService.selectCarInfoById(id));
    }

    /**
     * 新增车辆信息 DATA_CUSTOMER_INFO 外联
     */
    @PreAuthorize(hasPermi = "buss:carInfo:add")
    @Log(title = "车辆信息 DATA_CUSTOMER_INFO 外联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarInfo carInfo)
    {
        return toAjax(carInfoService.insertCarInfo(carInfo));
    }

    /**
     * 修改车辆信息 DATA_CUSTOMER_INFO 外联
     */
    @PreAuthorize(hasPermi = "buss:carInfo:edit")
    @Log(title = "车辆信息 DATA_CUSTOMER_INFO 外联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarInfo carInfo)
    {
        return toAjax(carInfoService.updateCarInfo(carInfo));
    }

    /**
     * 删除车辆信息 DATA_CUSTOMER_INFO 外联
     */
    @PreAuthorize(hasPermi = "buss:carInfo:remove")
    @Log(title = "车辆信息 DATA_CUSTOMER_INFO 外联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(carInfoService.deleteCarInfoByIds(ids));
    }
}
